package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.IsUserLoginAppByOpenIdBean;
import com.ymatou.iapi.userservice.service.IsUserLoginAppByOpenIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*用户是否登录过APP-OpenId
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IsUserLoginAppByOpenId{
	private static IsUserLoginAppByOpenIdBean isuserloginappbyopenidBean;
	private static IsUserLoginAppByOpenIdCall isuserloginappbyopenidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户是否登录过APP-OpenId");
	}

	@Before
	public void caseUp() {
		isuserloginappbyopenidBean=new IsUserLoginAppByOpenIdBean();
		isuserloginappbyopenidCall=new IsUserLoginAppByOpenIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(isuserloginappbyopenidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IsUserLoginAppByOpenId_001() {
		Logger.start(true,"用户登录过APP-OpenId,成功");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Logger.comment(phone+":用户WX注册");
			WeiXinUserRequestDtoBean wx = JUserCallService.initWeiXinUserRequestDtoBeanForRegister();
			wx.setMobile(phone);
			WeiXinUserRequestDtoCall urrc = JUserCallService.weiXinUserRequestDto(wx);
			Integer uid=urrc.getUid();
			isuserloginappbyopenidBean.setOpenId(wx.getOId());
			isuserloginappbyopenidCall.setData(isuserloginappbyopenidBean);
			isuserloginappbyopenidCall.callService();			
			Logger.verifyEquals("true", isuserloginappbyopenidCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", isuserloginappbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			boolean onceLoginApp = isuserloginappbyopenidCall.getJsonObject().get("Result").getAsJsonObject().get("onceLoginApp").getAsBoolean();
			Logger.verifyEquals(true, onceLoginApp, "验证onceLoginApp");
			Integer userId = isuserloginappbyopenidCall.getJsonObject().get("Result").getAsJsonObject().get("userId").getAsInt();
			Logger.verifyEquals(uid, userId, "验证userId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IsUserLoginAppByOpenId_002() {
		Logger.start(true,"不传参数失败");
		try {
			isuserloginappbyopenidCall.setData(isuserloginappbyopenidBean);
			isuserloginappbyopenidCall.callService();			
			Logger.verifyEquals("false", isuserloginappbyopenidCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", isuserloginappbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IsUserLoginAppByOpenId_003() {
		Logger.start(true,"用户没登录过APP-OpenId,返回false");
		try {
			isuserloginappbyopenidBean.setOpenId(TestDataManager.getRandomNumToHex(15));
			isuserloginappbyopenidCall.setData(isuserloginappbyopenidBean);
			isuserloginappbyopenidCall.callService();			
			Logger.verifyEquals("true", isuserloginappbyopenidCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", isuserloginappbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			boolean onceLoginApp = isuserloginappbyopenidCall.getJsonObject().get("Result").getAsJsonObject().get("onceLoginApp").getAsBoolean();
			Logger.verifyEquals(false, onceLoginApp, "验证onceLoginApp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}